/**数据连接*/
/**
 *   安装 mysql 模块
 *   cnpm install mysql --save
 * */

/**
 *   1. 引用驱动模块
 *   2. 设置连接配置信息
 *   3. 建立连接
 *   4. 执行查询
 *   4. 关闭连接
 * **/
var mysql = require('mysql')

var connection = mysql.createConnection({
    host:'localhost',
    user:'root',
    password:'123456',
    database:'demo'
})

connection.connect();

/**1. 增加 */
/*var sql ="insert into user(`username`) value(?)";
* var params=['test00345'];
* */

/**2. 修改 */
/*var sql ="UPDATE `demo`.`user`\n" +
    "SET\n" +
    "`username` = ?,\n" +
    "`password` = ?\n" +
    "WHERE `user_id` =?\n"

var params=['test0034','555',3];*/


/** 3. 删除 */

var sql = "DELETE FROM `demo`.`user`\n" +
    "WHERE user_id=?";
var params = [4];


connection.query(sql,params,function (error,result) {
   console.log(result);
})

connection.end();